<template>
    <div>
        <!-- 头部面包屑 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
            <el-breadcrumb-item>权限列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 卡片视图 -->
        <el-card class="box-card">
            <!-- 权限列表 -->
            <el-table
                :data="CompetenceList"
                stripe
                style="width: 100%"
                border
                :row-style="setHeight"
                >
                <el-table-column
                label="#"
                width="50"
                type="index"
                >
                </el-table-column>
                <el-table-column
                prop="authName"
                label="权限名称"
                min-width>
                </el-table-column>
                <el-table-column
                prop="path"
                label="路径"
                min-width>
                </el-table-column>
                <el-table-column
                prop="level"
                label="权限等级"
                min-width>
                <!-- 使用作用域插槽获取到当前行的所有数据 -->
                <!-- 其中scope.row 的 row属性则是当前行的所有数据 -->
                    <template scope="{row:{level}}">
                        <el-tag v-if="level==='0'">一级</el-tag>
                        <el-tag type="success" v-if="level==='1'">二级</el-tag>
                        <el-tag type="warning" v-if="level==='2'">三级</el-tag>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
export default {
    name:'Rights',
    data(){
        return {
            // 权限管理列表的数据
            CompetenceList:[],

        }
    },
    methods:{
        // 获取权限列表方法
        async getCompetenceList(){
            const {data:res} = await this.$axios.get('/rights/list');
            if(res.meta.status!==200)return this.$message.error(res.meta.msg);
            
            this.CompetenceList = res.data;
        },
        // 设置表格样式中的高度
        setHeight({row,rowIndex}){
            let styleJson = {
                'height': '52.33px',
            };
            return styleJson
        }
    },
    // 初始化后组件重新刷新获取权限列表
    created() {
        this.getCompetenceList()
    },
}
</script>

<style lang="less" scoped>

</style>